package stdio.costa.imoca.servlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import stdio.costa.imoca.model.MocaMicroBlog;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.core.util.MultivaluedMapImpl;

@Controller
@RequestMapping(value = "/weibo")
public class WeiboController extends BaseController {

	@RequestMapping(value = "/publish_weibo")
	public String getWeibofriendlist(final HttpServletRequest request,
			final HttpServletResponse response, final ModelMap result)
			throws Exception {

		String accessTokenCode = (String) request.getSession(false)
				.getAttribute("accessToken");

		ClientConfig config = new DefaultClientConfig();
		Client client = Client.create(config);
		WebResource service = client.resource(getBaseURI());
		MultivaluedMap<String, String> param = new MultivaluedMapImpl();
		param.add("accessToken", accessTokenCode);

		MocaMicroBlog mocaMicroBlog = service.path("weibo").path("publish_weibo")
				.queryParams(param).type(MediaType.APPLICATION_FORM_URLENCODED)
				.accept(MediaType.APPLICATION_JSON).get(MocaMicroBlog.class);
		
		return null;
	}
}
